﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addrbook_personal_index.aspx.cs" Inherits="Ccit.OA.AddrBook.addrbook_personal_index" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v8.1" namespace="DevExpress.Web.ASPxGridView" tagprefix="dxwgv" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v8.1" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>通讯录-个人通讯录</title>
    <script language="javascript" type="text/javascript" src="../script/jquery.js"></script>
    <script language="javascript" type="text/javascript" src="../script/StringClass_Ext.js"></script>
    <script language="javascript" type="text/javascript" src="../script/jsonlib.js"></script>
    <script language="javascript" src="../script/jwindow.js"></script>
    <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>
    <script type="text/javascript">
         //删除
		function doDel()
		{  
		      var  vId = document.getElementById("_hidTypeID").value; 
		        if(vId!="")
		        {
		            if(confirm("是否确定要删除当前选定的信息?")) 
                             PageMethods.DoOperate(vId,ClientCallBack);    
                }
                else
                {
                    alert("尚未有您要删除的数据");
                } 
		} 
		function ClientCallBack(vResult)
		{
		   if(vResult!="-998")
		   {
		        alert("操作成功!");
		         __doPostBack("lnbQuery","");
		        return true;
		   }
		   else
		   {
		        alert("系统繁忙,请稍后再继续操作!");
		        return false;
		   }
		}
		function doOperate(vSId)
		{
		     var oPageParam="Id="+vSId;
             var oEncodeParam=base64encode(oPageParam);
             var strUrl="addrbook_personal_edit.aspx?"+oEncodeParam;
             window.location.href = strUrl;
		}
        //复选框选择
         var objState ; 
        function doDataGridItemSel( obj )
        {
          if ( objState != null )
          {
             objState.style.color = "";
             objState.style.backgroundColor = "";
          } 
          obj.style.color = "#fffeee";
          obj.style.backgroundColor = "#a0a0a0";        
          objState = obj;		                       
        }	
        function OnGridSelectionChanged(){           
            dgMain.GetSelectedFieldValues("PKID",OnGridSelectionComplete);
        }
        
        function OnGridSelectionComplete(values){
            document.getElementById("_hidTypeID").value=values;            
        }
        function DoSetGroup()
        {
              var strUrl="addrbook_group_set.aspx";
              OpenWindow(strUrl,"","400","300");
        }
        function DoSelectGroup()
        {
               var  vId = document.getElementById("_hidTypeID").value; 
		        if(vId!="")
		        {
		                var oPageParam="Id="+vId;
                        var oEncodeParam=base64encode(oPageParam);
		                var strUrl="addrbook_group_select.aspx?"+oEncodeParam;
                        OpenWindow(strUrl,"","400","200");
                }
                else
                {
                    alert("尚未有您要调整的数据");
                } 
              
        }
         var exApp  = null;
         var exWBook = null;
         var exWSheet = null;
     /*--- 每次更新的数据量(行) ---*/
         var vNum=350;
           function doImportExcel()
     {
        if(docheck())
        {
            if(!confirm("执行速度受数据量影响，导入期间请耐心等候，是否确认执行该操作？"))
            {                
                return;
            }
            var vname=exWBook.worksheets(1).name;
            exWSheet=exWBook.Worksheets(vname);
            var i=2;
            var vArr=new Array();
            while(exWSheet.cells(i,1).value!=null&&i<vNum)
            {
                var MsAddBook={};
                MsAddBook.UserId=(exWSheet.cells(i,1).value!=null) ? exWSheet.cells(i,1).value : "";
                MsAddBook.Name=(exWSheet.cells(i,2).value!=null) ? exWSheet.cells(i,2).value:"";
                MsAddBook.Call=(exWSheet.cells(i,3).value!=null) ? exWSheet.cells(i,3).value : "";
                MsAddBook.Birthday=(exWSheet.cells(i,4).value!=null) ? exWSheet.cells(i,4).value : "";
                MsAddBook.GroupId=(exWSheet.cells(i,5).value!=null) ? exWSheet.cells(i,5).value : "";
                MsAddBook.Company=(exWSheet.cells(i,6).value!=null) ? exWSheet.cells(i,6).value : "";
                MsAddBook.DeptName = (exWSheet.cells(i,7).value!=null) ? exWSheet.cells(i,7).value : ""; 
                MsAddBook.PostName=(exWSheet.cells(i,8).value!=null) ? exWSheet.cells(i,8).value : ""; 
                MsAddBook.Telphone=(exWSheet.cells(i,9).value!=null) ? exWSheet.cells(i,9).value : "";
                MsAddBook.Comtel=(exWSheet.cells(i,10).value!=null) ? exWSheet.cells(i,10).value:"";
                MsAddBook.Ftel=(exWSheet.cells(i,11).value!=null) ? exWSheet.cells(i,11).value : "";
                MsAddBook.Fax=(exWSheet.cells(i,12).value!=null) ? exWSheet.cells(i,12).value : "";
                MsAddBook.Maddress=(exWSheet.cells(i,13).value!=null) ? exWSheet.cells(i,13).value : "";
                MsAddBook.Postcode=(exWSheet.cells(i,14).value!=null) ? exWSheet.cells(i,14).value : "";
                MsAddBook.msnname = (exWSheet.cells(i,15).value!=null) ? exWSheet.cells(i,15).value : ""; 
                MsAddBook.qname=(exWSheet.cells(i,16).value!=null) ? exWSheet.cells(i,16).value : ""; 
                MsAddBook.email=(exWSheet.cells(i,17).value!=null) ? exWSheet.cells(i,17).value : "";
                MsAddBook.makenum=(exWSheet.cells(i,18).value!=null) ? exWSheet.cells(i,18).value:"";
                MsAddBook.url=(exWSheet.cells(i,19).value!=null) ? exWSheet.cells(i,19).value : "";
                MsAddBook.remark=(exWSheet.cells(i,20).value!=null) ? exWSheet.cells(i,20).value : "";  
                vArr.push(MsAddBook);
                i++;
            }
            if(vArr.length>0)
            {
                var jsonAddBooks=JSON.stringify(vArr,function(key,value){return value;});
                PageMethods.SaveImport(jsonAddBooks,ClientCallBack);
            }
            else
            {
                dispose();
                alert("您要导入的个人通讯录里没有数据!");
            }
        }
     }
      function docheck()
     {
        var vFilePath = document.getElementById("t_file").value;
        if(vFilePath == "")
        {
           alert("请选择要导入的Excel文件路径！");   
           return false;
        }
        if(vFilePath.substring(vFilePath.length - 4,vFilePath.length) != ".xls" )
        {
            alert("请确定您选择的文件是一个Excel文件！");
            return false;
        }
        exApp = new ActiveXObject("Excel.Application");
        exWBook=exApp.workbooks.open(vFilePath);
         /*-- 统计打开的Excel文件中 Sheet 的个数 --*/
            var scount=exWBook.worksheets.count;
            if(scount == 0)
            {
                dispose();
                alert("您选择的Excel文件中不包含要导出数据的信息！");
                return false;
            }
            return true;
        }
      
        /*-- 关闭Excel --*/
        function dispose()
        {
            if(exWBook!=null)
            {
                exWBook.Close(savechanges=false);
                exWBook=null;
            }
            if(exApp!=null)
            {
                exApp.Quit();
                exApp=null;
            }
        }
        
    </script>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager> 
    <input type="hidden" id="_hidTypeID" runat="server" />
   <table class="tbToolbar" cellpadding="0" cellspacing="0" width="98%" align="center">
                    <tr>
                        <td align="left">
                            <div class="tbSeparator"></div>
                        </td>
                        <td width="100%" class="titlebar">  
                            个人通讯录列表
                        </td>                
                        <td align="right">
                            <nobr>
                                关键字:                                  
                                <asp:TextBox ID="txttName" CssClass="input" Width="100" runat="server"></asp:TextBox>                                                     
                                &nbsp;<asp:LinkButton ID="lnbQuery" CssClass="linktext" runat="server" onclick="lnbQuery_Click" 
                                 >
                                    <img src="../images/toolbar/search.gif" />查询
                                </asp:LinkButton>  
                                <a  id="lnbAdd" Runat="server" class="linktext"  
                                href="javascript:doOperate('0')">
							        <img src="../images/toolbar/new.gif" border="0">新增
						        </a>
						         <a  id="lnbDel" Runat="server" class="linktext"  
                                href="javascript:doDel()">
							        <img src="../images/toolbar/Delete.gif" border="0">删除
						        </a>
						        <a  id="A1" Runat="server" class="linktext"  
                                href="javascript:DoSelectGroup()">
							        <img src="../images/toolbar/bdgsdy/view.gif" border="0">调整分组
						        </a>
						        <a  id="A2" Runat="server" class="linktext"  
                                href="javascript:DoSetGroup()">
							        <img src="../images/toolbar/view.gif" border="0">设置分组
						        </a>
					            <input name="upload" type="file" style="position:absolute;filter:alpha(opacity=0);width:10px; cursor:hand" id="t_file" onchange="javascript:doImportExcel();">
						        <img src="../images/toolbar/FBACK.GIF" border="0">导入	&nbsp;					       
						        <asp:LinkButton ID="lnbExportExcel" CssClass="linktext" runat="server" 
                                onclick="lnbExportExcel_Click"> 
							        <img src="../images/toolbar/fforward.gif" border="0">导出 
						        </asp:LinkButton>
                             </nobr>
                        </td> 
                    </tr>
       </table>
       <table cellpadding="0" cellspacing="0" width="98%" align="center">                 
                                <tr>
                                    <td colspan="3" width="100%">
                                      <dxwgv:ASPxGridView ID="dgMain" runat="server"
                                AutoGenerateColumns="False" Width="100%" KeyFieldName="PKID" onhtmlrowcreated="dgMain_HtmlRowCreated" 
                                            Settings-ShowGroupPanel="true">  
                                            <SettingsText GroupPanel="分组栏" />                                                                                       
                                  <%-- 设置页脚中分页 --%>
            

                                            <Columns>
                                                 <dxwgv:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0" Width="4%">
                                                    <HeaderTemplate>
                                                        <input type="checkbox" id="chbCheck" runat="server" onclick="dgMain.SelectAllRowsOnPage(this.checked);"
                                                            style="vertical-align: middle;" title="Select/Unselect all rows on the page"></input>
                                                    </HeaderTemplate>
                                                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" HorizontalAlign="Center">
                                                        <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                                                    </HeaderStyle>
                                                </dxwgv:GridViewCommandColumn>
                                                <dxwgv:GridViewDataTextColumn    Caption="标志" VisibleIndex="1" width="5%"   FieldName="BZ">
                                                 <HeaderStyle HorizontalAlign="Center" />
                                                 <CellStyle HorizontalAlign="left"></CellStyle>
                                                 <DataItemTemplate> 
							                            <img src=""  align="middle" border="0" id="ImgView" alt=""  runat="server"/>                                
                                                 </DataItemTemplate>
                                                </dxwgv:GridViewDataTextColumn>
                                                <dxwgv:GridViewDataTextColumn Caption="名称" VisibleIndex="2" width="7%" FieldName="Name">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="left"></CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                 <dxwgv:GridViewDataTextColumn Caption="单位" VisibleIndex="3" width="15%" FieldName="Company">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="left" Wrap="False"></CellStyle>
                                                </dxwgv:GridViewDataTextColumn>  
                                                 <dxwgv:GridViewDataTextColumn Caption="手机" VisibleIndex="4" width="11%" FieldName="Telphone">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="right"></CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                 <dxwgv:GridViewDataTextColumn Caption="办公电话" VisibleIndex="5" width="12%" FieldName="ComTel">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="right"></CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                 <dxwgv:GridViewDataTextColumn Caption="家庭电话" VisibleIndex="6" width="10%" FieldName="FTel">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="right"></CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                 <dxwgv:GridViewDataTextColumn Caption="Email" VisibleIndex="7" width="15%" FieldName="email">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="left" Wrap="False"></CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                  <dxwgv:GridViewDataTextColumn Caption="分组" VisibleIndex="8" width="8%" FieldName="AGroupName">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="Center"></CellStyle>
                                                </dxwgv:GridViewDataTextColumn>
                                                 <dxwgv:GridViewDataTextColumn  VisibleIndex="10"  Visible="false" FieldName="GroupId">                                                 
                                                </dxwgv:GridViewDataTextColumn>
                                                 <dxwgv:GridViewDataTextColumn Caption="操作" VisibleIndex="9" width="6%">
                                                  <HeaderStyle HorizontalAlign="Center" />
                                                  <CellStyle HorizontalAlign="Center"></CellStyle>
                                                   <DataItemTemplate>
                                                   <nobr> 
                                                        <a id="lnbEdit" runat="server">修改</a>   
                                                   </nobr>
                                                   </DataItemTemplate>
                                                </dxwgv:GridViewDataTextColumn>
                                            </Columns>
                                             <%-- 复选框选择脚本事件 --%> 
                                                    
                                    <Settings ShowGroupPanel="True" ></Settings>
                                        
                                                    <ClientSideEvents SelectionChanged="function(s,e){OnGridSelectionChanged();}" />
                                                        <SettingsPager PageSize=15 Mode="ShowPager" AlwaysShowPager=true
                                 FirstPageButton-Visible=true LastPageButton-Visible=true  
                                 FirstPageButton-Image-AlternateText="" LastPageButton-Image-AlternateText="尾页"
                                 NumericButtonCount=5  SEOFriendly="Disabled"
                                 PrevPageButton-Visible="true" NextPageButton-Visible="true"
                                 ShowSeparators=true Position="Bottom">
                                    <FirstPageButton Visible="True"></FirstPageButton>
                                    <LastPageButton Visible="True">
                                    <Image AlternateText="尾页"></Image>
                                    </LastPageButton>
                            </SettingsPager>
                                 
                            <%-- 复选框选择脚本事件--%>
                            <ClientSideEvents SelectionChanged="function(s,e){OnGridSelectionChanged();}"
                                 CustomizationWindowCloseUp="function(s,e){ UpdateCustomizationWindowValue();}"
                             />
                            
                            <%-- 设置行样式--%>
                            <Styles>
                                <Row CssClass=""></Row>
                                <AlternatingRow  CssClass="" Enabled="true"/>
                                <SelectedRow  CssClass=""></SelectedRow>                
                            </Styles>
                            <%--  显示过滤行--%>
                            <Settings ShowFilterRow="false" ShowPreview="True"/>
                            
                            <%-- 可调整列宽--%>
                            <SettingsBehavior ColumnResizeMode="Control" />
                            
                            <%-- 自定义表头--%>
                            <SettingsCustomizationWindow Enabled="true" />
                                        </dxwgv:ASPxGridView>
                                    </td>
                                </tr>
                            </table>
    </ccit:ActionForm>
</body>
</html>
